package com.work.cos.web.controller.api.pr;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.work.cos.domain.vo.ComServiceResVo;
import com.work.cos.service.interfc.pr.IPrProductService;
import com.work.cos.service.interfc.pr.IPrTypeFirstService;
import com.work.cos.service.interfc.pr.IPrTypeSecondService;

@RestController
@RequestMapping("/api/home")
public class PrHomeApiController {

	private static Logger LOGGER = LoggerFactory.getLogger(PrHomeApiController.class);
	
	@Autowired
	private IPrTypeFirstService firstService;
	
	@Autowired
	private IPrTypeSecondService secondService;
	
	@Autowired
	private IPrProductService productService;

	/**
	 * 查看一级分类
	 * @return
	 */
	@PostMapping(value = "/first")
	public ComServiceResVo queryFirstList(){
		LOGGER.debug("query first type... ");
		return ComServiceResVo.returnList(firstService.getAllList());
	}
	
	/**
	 * 查看二级分类
	 * @param id
	 * @return
     */
	@PostMapping(value = "/second")
	public ComServiceResVo querySecondList(@RequestParam Long firstId){
		LOGGER.debug("query second type ... ");
		return ComServiceResVo.returnList(secondService.getListByFirstId(firstId));
	}
	
	/**
	 * 二级分类对应商品
	 * @param id
	 * @return
     */
	@PostMapping(value = "/second/product")
	public ComServiceResVo queryProductList(@RequestParam Long secondId){
		LOGGER.debug("query second type product ... ");
		return ComServiceResVo.returnList(productService.getListBySecondId(secondId));
	}
}
